const quest_url_list = [
    'https://www.baidu.com',
    'https://www.bilibili.com',
    'https://www.jd.com',
    'https://www.taobao.com',
    'https://www.tmall.com',
]
const mixQuestCount = 3 // 最大屏发请求个数

class QuestConcurrent {
    constructor(maxCount) {
        this.queueList = []
        this.maxCount = maxCount
        this.currentCount = 0 // 当前的并发个数
    }
    add(url) {
        return new Promise((resolve, reject) => {
            this.queueList.push({
                url,
                resolve,
                reject
            })
            this.run() // 运行
        })
    }
    run() {
        this.currentCount++;
        if (this.currentCount <= this.maxCount && this.queueList.length > 0) {
            const { url, resolve, reject } = this.queueList.shift()
            fetch(url).then(res => {
                resolve(res)
            }).catch(err => {
                reject(err)
            }).finally(() => {
                this.currentCount--
                this.run()
            })
        }

    }
}

const questConcurrent = new QuestConcurrent(mixQuestCount)

Promise.all(quest_url_list.map(item => questConcurrent.add(item))).then(res => {
    console.log(res, '结果')
})